/*****************************************************
** Author: 
** Date: 2020-06-28
*
*****************************************************/

#include "heap.h"
#include "comm.h"

unsigned char heap_user[6 * 1024];

/**
 * @brief
 * @param  None
 * @retval None
 */
void heap_test(void)
{
#if 1
	heap_hdl_t heap = heap_user;
	heap4_init(heap, sizeof(heap_user));

	unsigned char *ptr = heap4_malloc(heap, 1024);
	tc_log("ptr %p free heap %d", ptr, heap4_freeheapsize(heap));

	unsigned char *buff = heap4_malloc(heap, 2 * 1024);
	tc_log("buff %p free heap %d", buff, heap4_freeheapsize(heap));

	heap4_free(heap, ptr);
	tc_log("free heap %d min ever heap size %d", \
		   heap4_freeheapsize(heap), heap4_mineverfreeheapsize(heap));

	unsigned char *buff_new = heap4_realloc(heap, buff, 1 * 1024);
	tc_log("buff %p buff_new %p free heap %d min ever heap size %d", buff, buff_new, \
			heap4_freeheapsize(heap), heap4_mineverfreeheapsize(heap));

	heap4_blocklink_info(heap, "after heap4_realloc");

	if (buff_new == NULL)
		heap4_free(heap, buff);
	else
		heap4_free(heap, buff_new);

	tc_log("free heap %d min ever heap size %d", \
		   heap4_freeheapsize(heap), heap4_mineverfreeheapsize(heap));
#endif
}

/* End of file */



